***********************************
*                                 *
*  Carson, Cann, Yates, & Wright  *
*                                 *
*     Gender and Prosecutors      *
*                                 *
***********************************

clear all
use "/Users/DamonLaptop/Dropbox/Prosecutor Elections/Data_Gender/PolBeh Replication.dta"


*Heckman Model for Table 2
  heckprob femwins i.fem_match_pres viol_100k i.feminc i.nonpartisan i.openseat i.three_can mass_cult_con_est pctnonwt incum_years, select(femruns =  fematper1000 i.openseat i.nonpartisan  i.careofficial viol_100k mass_cult_con_est pctnonwt incum_years) 

  est store noyears
 
*Create Figure 1

preserve
collapse (mean) femwins (mean) femruns, by(elecyr)
gen pct_femwins = femwins*100
gen pct_femruns = femruns*100
drop if elecyr >=2020
line  pct_femruns pct_femwins elecyr
restore
 
 
 
*Descriptives for Table 1 and Appendix tables
  gen sample = e(sample)  
  
sum femwins femruns fem_match_pres viol_100k i.feminc i.nonpartisan i.openseat i.three_can mass_cult_con_est pctnonwt incum_years fematper1000 careofficial if sample==1
  
tab numcand  femruns if sample==1 ,col
tab numcand  femwins if sample==1 ,col
tab numcand  nonpart if sample==1 ,col
tab femruns openseat if sample==1, col
tab femwins openseat if sample==1, col

* Generate list of Districts for Appendix
 
 list district state elecyr if sample==1
   
  
* Average Marginal Effects for Figures

margins, dydx(fematper1000 i.openseat i.nonpartisan  i.careofficial  mass_cult_con_est  ) predict(psel)
marginsplot, horiz recast(scatter) name(g1, replace)
margins, dydx(viol_100k  pctnonwt incum_years) predict(psel)
marginsplot, horiz recast(scatter) name(g2, replace)

gr combine g1 g2, c(2)

  
  
margins, dydx(i.fem_match_pres i.feminc i.nonpartisan i.openseat i.three_can mass_cult_con_est  ) predict(pmarg)
marginsplot, horiz recast(scatter) name(g3, replace)
  
margins, dydx(viol_100k pctnonwt incum_years) predict(pmarg) 
marginsplot, horiz recast(scatter) name(g4, replace)

gr combine g3 g4, c(2)


*Robustness check with years

 heckprob femwins i.fem_match_pres viol_100k i.feminc i.nonpartisan i.openseat i.three_can mass_cult_con_est pctnonwt incum_years i.elecyr , select(femruns =  fematper1000 i.openseat i.nonpartisan  i.careofficial viol_100k mass_cult_con_est pctnonwt incum_years i.elecyr) 
 
 est store years
 
 lrtest years noyears

*Robustness check with Clustered SEs for districts
 heckprob femwins i.fem_match_pres viol_100k i.feminc i.nonpartisan i.openseat i.three_can mass_cult_con_est pctnonwt incum_years , select(femruns =  fematper1000 i.openseat i.nonpartisan  i.careofficial viol_100k mass_cult_con_est pctnonwt incum_years) cluster(district) 


*Robustness check without state_cult_con_est

 heckprob femwins i.fem_match_pres viol_100k i.feminc i.nonpartisan i.openseat i.three_can  pctnonwt incum_years , select(femruns =  fematper1000 i.openseat i.nonpartisan  i.careofficial viol_100k  pctnonwt incum_years) 


